﻿using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using UCL.Powersource;
using UCL.Powersource.Analysis;
using UCL.Powersource.Mock;
using UCL.Powersource.Statistics;
using UCL.Powersource.Statistics.CodeIndex;

namespace Powersource_UnitTests.StatisticsTest
{
    [TestClass]
    public class CodeIndexTest
    {
        [TestMethod]
        public void TestNumberOfClasses()
        {
            var dummyTPCC = new DummyTeamProjectCollectionConfiguration();
            var pr1 = dummyTPCC.TeamProjectConfigurations[0];
            var timeframe = dummyTPCC._ProjectCollectionTimeFrames[0];
            NumberOfClassesStats myStats = new NumberOfClassesStats();

            myStats.Resolve(pr1, true);
            Assert.AreNotEqual(0, myStats.TeamResults[pr1][timeframe].Value,
                "There are no classes thrown by the results of the test"); 
            Assert.AreEqual(6, myStats.TeamResults[pr1][timeframe].Value, 
                "The number of classes thrown by the test does not match the " + 
                    "number of classes in the assemlbly");
        }

        [TestMethod]
        public void TestNumberOfMethods()
        {
            var dummyTPCC = new DummyTeamProjectCollectionConfiguration();
            var pr1 = dummyTPCC.TeamProjectConfigurations[0];
            var timeframe = dummyTPCC._ProjectCollectionTimeFrames[0];
            NumberOfMethodsStats myStats = new NumberOfMethodsStats();

            myStats.Resolve(pr1, true);
            Assert.AreNotEqual(0, myStats.TeamResults[pr1][timeframe].Value,
                "There are no methods thrown by the results of the test");
            Assert.AreEqual(12, myStats.TeamResults[pr1][timeframe].Value,
                "The number of methods thrown by the test does not match the " +
                    "number of methods in the assemlbly");
        }

        [TestMethod]
        public void TestNumberOfSubClasses()
        {
            var dummyTPCC = new DummyTeamProjectCollectionConfiguration();
            var pr1 = dummyTPCC.TeamProjectConfigurations[0];
            var timeframe = dummyTPCC._ProjectCollectionTimeFrames[0];
            NumberOfClassesStats myStats = new NumberOfClassesStats();

            myStats.Resolve(pr1, true);
            Assert.AreNotEqual(0, myStats.TeamResults[pr1][timeframe].Value,
                "There are no subclasses thrown by the results of the test");
            Assert.AreEqual(4, myStats.TeamResults[pr1][timeframe].Value,
                "The number of subclasses thrown by the test does not match the " +
                    "number of subclasses in the assemlbly");
        }

        [TestMethod]
        public void TestDepthOfInheritance()
        {
            var dummyTPCC = new DummyTeamProjectCollectionConfiguration();
            var pr1 = dummyTPCC.TeamProjectConfigurations[0];
            var timeframe = dummyTPCC._ProjectCollectionTimeFrames[0];
            DepthOfInheritance myStats = new DepthOfInheritance();

            myStats.Resolve(pr1, true);
            Assert.AreEqual(2, myStats.TeamResults[pr1][timeframe].Value,
                "The maximum depth of inheritance thrown by the test does " +
                    "not match the expected one");
        }

        [TestMethod]
        public void TestResponseForClass()
        {
            var dummyTPCC = new DummyTeamProjectCollectionConfiguration();
            var pr1 = dummyTPCC.TeamProjectConfigurations[0];
            var timeframe = dummyTPCC._ProjectCollectionTimeFrames[0];

            RFCStatisticAverage myStat = new RFCStatisticAverage();
            myStat.Resolve(pr1, timeframe);
            Assert.AreEqual(3.6, myStat.TeamResults[pr1][timeframe].Value, "");

            RFCStatisticMaximum anotherStat = new RFCStatisticMaximum();
            anotherStat.Resolve(pr1, timeframe);
            Assert.AreEqual(7.0, anotherStat.TeamResults[pr1][timeframe].Value, "");
        }

        [TestMethod]
        public void TestRFCForCollection()
        {
            var dummyTPCC = new DummyTeamProjectCollectionConfiguration();
            var timeframe = dummyTPCC._ProjectCollectionTimeFrames[0];
            
            RFCStatisticMinimum myStat = new RFCStatisticMinimum();
            myStat.Resolve(dummyTPCC, timeframe);
            Assert.AreEqual(dummyTPCC.TeamProjectConfigurations.FindAll(proj => proj.IsValidForStatistic).Count, 
                myStat.TeamResults.Count, "");
        }

        [TestMethod]
        public void TestRFCForSeveralTimeFrames()
        {
            var dummyTPCC = new DummyTeamProjectCollectionConfiguration();
            var pr1 = dummyTPCC.TeamProjectConfigurations[0];

            RFCStatisticMedian myStat = new RFCStatisticMedian();
            myStat.Resolve(pr1);
            Assert.AreEqual(new List<ITimeFrame>(pr1.ProjectTimeframes).Count,  myStat.TeamResults[pr1].Count, "");

            RFCStatisticAverage anotherStat = new RFCStatisticAverage();
            anotherStat.Resolve(pr1);
            Assert.AreEqual(new List<ITimeFrame>(pr1.ProjectTimeframes).Count, anotherStat.TeamResults[pr1].Count, "");
        }
    }
}
